<?php


namespace app\test\controller;


class Admin
{
    public function getip()
    {
        var_dump(request());
    }

    public function post1()
    {

        // 新增一条数据
        $admin = new \app\model\Admin();
        $admin->account = 12312322;
        $admin->password = 123123;
        $dd = $admin->save();
        var_dump($dd);

    }

    public function post2()
    {

        $data['account00'] = 'thinkphp';
        $data['passwordss'] = 100;
        $user = new \app\model\Admin();
        $user->save($data);
        var_dump($user->aid);

    }

    public function post3()
    {
        $user = new \app\model\Admin();

        $list = [
            ['account' => 'thinkphp1', 'password' => 'thinkphp@qq.com'],
            ['account' => 'onethink', 'email' => 'onethink@qq.com']
        ];
        $dd = $user->saveAll($list);
        var_dump($dd->all());

    }

    public function post4()
    {
        $user = \app\model\Admin::create(
            ['account' => 'thinkphp1', 'password' => 'thinkphp@qq.com']
        );
        var_dump($user->aid);
    }

    public function update1()
    {
        $user = \app\model\Admin::update(
            ['aid' => 1, 'account' => 'thinkphp1', 'password' => 'thinkphp@qq.com']
        );
        var_dump($user);
    }

    //先查再删
    public function delete1()
    {
        $user = \app\model\Admin::find(1);
        var_dump($user);
//        var_dump($user->delete());
    }

    //直接删
    public function delete2()
    {
        $user = \app\model\Admin::destroy(1);
        var_dump($user);
    }


    public function get()
    {
        // 根据主键获取多个数据
        $list = \app\model\Admin::select([1, 2, 3]);
// 对数据集进行遍历操作
        foreach ($list as $key => $user) {
            echo $user->account."|";
        }
    }

    public function get1()
    {
        $user = \app\model\Admin::getByAccount('thinkphp1');
//        $dd = $user->toJson();
//        echo  $dd;die;

        $dd = $user->toArray();

        echo json_encode($dd,256);
    }



}